package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsUser;
import com.qf.pojo.DtsUserAccount;
import com.qf.service.DtsUserAccountService;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * projectName:workspace_6
 * author:hyn
 * time:2021/11/30 11:47
 * description:
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/admin/user")
public class AdminUserController {
    @Autowired
    private DtsUserService userService;
    //会员列表
    @RequestMapping("list")
    public Object list(String username, String mobile,
                       @RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                       @RequestParam(name = "limit",required = false,defaultValue = "20") Integer limit,
                       @RequestParam(name = "sort",required = false,defaultValue = "add_time") String sort,
                       @RequestParam(name = "order",required = false,defaultValue = "desc") String order
    ){
        IPage<DtsUser> users = userService.findAll(username,mobile,limit,page,sort,order);
        HashMap<String, Object> data = new HashMap<>();
        data.put("total",users.getTotal());
        data.put("items",users.getRecords());
        return ResponseUtil.ok(data);
    }
    @Autowired
    private DtsUserAccountService userAccountService;
    //会员审批
    @RequestMapping("approveAgency")
    public Object approveAgency(@RequestBody DtsUserAccount userAccount){
        //status 3代理申请 2 注销 1 禁用 0 可用 {userId=169, settlementRate=1233}
        //user_level 1  VIP用户 2 代理 0普通
        //status = 0，user_level = 2
        System.out.println(userAccount);
        return userService.saveStatusAndUserLevel(userAccount);


    }
    //推广代理
    @RequestMapping("detailApprove")
    public Object detailApprove(Integer id){
        if(id == null){
            return ResponseUtil.badArgument();
        }
        DtsUserAccount userAccount = userAccountService.findByUserId(id);
        return ResponseUtil.ok(userAccount);
    }
}
